#!/bin/bash

# postinst script for driver-network-qlc
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:bin $BASEDIR/usr/share/man/man4d
	chown root:bin $BASEDIR/usr/share/man
	chown root:sys $BASEDIR/kernel/misc/qlc
	chown root:sys $BASEDIR/kernel/misc/qlc/amd64
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/qlc.conf ] && rm -f $BASEDIR/kernel/drv/qlc.conf
	else
	    [ -f $BASEDIR/kernel/drv/qlc.conf ] || cp -ax $BASEDIR/usr/share/doc/driver-network-qlc/examples/qlc.conf $BASEDIR/kernel/drv/qlc.conf
	    chmod 0644 "$BASEDIR/kernel/drv/qlc.conf"
	    chown root:sys "$BASEDIR/kernel/drv/qlc.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/qlc ] && rm -f $BASEDIR/kernel/drv/amd64/qlc
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/qlc"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/qlc"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/qlge ] && rm -f $BASEDIR/kernel/drv/amd64/qlge
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/qlge"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/qlge"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2200 ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2200
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2200"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2200"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2300 ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2300
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2300"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2300"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2400 ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2400
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2400"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2400"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2500 ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2500
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2500"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2500"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2700 ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2700
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2700"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_2700"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_6322 ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_6322
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_6322"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_6322"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8100 ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8100
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8100"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8100"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8301fc ] && rm -f $BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8301fc
	else
	    chmod 0755 "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8301fc"
	    chown root:sys "$BASEDIR/kernel/misc/qlc/amd64/qlc_fw_8301fc"
	fi
	[ "$ZONEINST" = "1" ] || (grep -c "^qlc " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -c 'fibre-channel' -i '"pci1077,2200" "pci1077,2300" "pci1077,2312" "pci1077,2322" "pci1077,2422" "pciex1077,2031" "pciex1077,2071" "pciex1077,2261" "pciex1077,2432" "pciex1077,2532" "pciex1077,5432" "pciex1077,8001" "pciex1077,8021"' -m '* 0666 root sys' qlc ) )
	[ "$ZONEINST" = "1" ] || (grep -c "^qlge " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -i '"pciex1077,8000"' -m '* 0666 root sys' qlge ) )
	
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

